package Limit.Event.Easter;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import l1j.server.L1DatabaseFactory;
import l1j.server.server.utils.SQLUtil;

public class Event_EasterTable 
{

	private static Event_EasterTable _instance;
	
	public static Event_EasterTable getInstance() 
	{
		if (_instance == null)
		{
			_instance = new Event_EasterTable();
		}
		return _instance;
	}
	
	public void getStart()
	{
		Load();
	}
	
	private int[][] _itemArray1 = new int[8][4];
	private int[][] _itemArray2 = new int[8][4];
	private int[][] _itemArray3 = new int[8][4];
	private int[][] _itemArray4 = new int[8][4];
	
	public int[][] getItemArray1()
	{
		return _itemArray1;
	}
	
	public int[][] getItemArray2()
	{
		return _itemArray2;
	}
	
	public int[][] getItemArray3()
	{
		return _itemArray3;
	}
	
	public int[][] getItemArray4()
	{
		return _itemArray4;
	}
	
	public void Load() 
	{
		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		int i;
		int k;
		
		for(int j = 1; j < 5; j++)
		{
			i = 0;
			try 
			{
				con = L1DatabaseFactory.getInstance().getConnection();
				pstm = con.prepareStatement("SELECT * FROM Event_Easter WHERE Rank ="+j);
				rs = pstm.executeQuery();
				
				while (rs.next())
				{
					k = 0;
					if ( j == 1)
					{
						_itemArray1[i][k] = rs.getInt("Item_id");
						_itemArray1[i][++k] = rs.getInt("Percentage");
						_itemArray1[i][++k] = rs.getInt("Count");
						_itemArray1[i][++k] = rs.getInt("img");
					}
					if ( j == 2)
					{
						_itemArray2[i][k] = rs.getInt("Item_id");
						_itemArray2[i][++k] = rs.getInt("Percentage");
						_itemArray2[i][++k] = rs.getInt("Count");
						_itemArray2[i][++k] = rs.getInt("img");
					}
					if ( j == 3)
					{
						_itemArray3[i][k] = rs.getInt("Item_id");
						_itemArray3[i][++k] = rs.getInt("Percentage");
						_itemArray3[i][++k] = rs.getInt("Count");
						_itemArray3[i][++k] = rs.getInt("img");
					}
					if ( j == 4)
					{
						_itemArray4[i][k] = rs.getInt("Item_id");
						_itemArray4[i][++k] = rs.getInt("Percentage");
						_itemArray4[i][++k] = rs.getInt("Count");
						_itemArray4[i][++k] = rs.getInt("img");
					}
						i++;
				}
			}
			catch (SQLException e) 
			{
				System.out.print(e.getMessage());
			}
			finally 
			{
				SQLUtil.close(rs, pstm, con);
			}		
		}
	}
}
